import React, { useEffect } from 'react';
import { connect } from 'umi';
import { Form, Icon, Divider } from 'antd';
import { formItemLayout } from '@/components/UserForm';

import Form1 from '@/pages/User/Confidential/components/Form1';
import Form2 from '@/pages/User/Confidential/components/Form2';
import Form3 from '@/pages/User/Confidential/components/Form3';
import Form4 from '@/pages/User/Confidential/components/Form4';
import Form5 from '@/pages/User/Confidential/components/Form5';
import Form6 from '@/pages/User/Confidential/components/Form6';
import Form7 from '@/pages/User/Confidential/components/Form7';

const Resume = ({
    form,
    taletData, // 表单数据
    // asian = [], // 籍贯项数据
    // readonly = null,
    disabled = false, // 禁用设置
    sytleSetting = 'true', // 是否配置类似候选人详情样式formitem宽度
    user,
    dictionary,
    dispatch,
    required = false
}) => {
    // const { getFieldDecorator } = form;
    const { currentUser = {} } = user;
    const { companyId: userCompanyId } = currentUser;
    // 公司判断表单渲染是新加坡还是厦门  如果是首次创建简历 公司为登录者的公司id 如果编辑简历 公司为简历者自身的公司id
    const { companyId = userCompanyId, ...others } = taletData;
    const initialFormInfo = { ...others, companyId };
    // let subFormProps;
    const subFormProps = { form, dict: dictionary, initialFormInfo, disabled, required };
    const { talentFile = [] } = taletData;
    // 获取简历信息数据字典
    const getDict = () => {
        dispatch({
            type: 'dictionary/fetchDictionaryList',
            payload: {
                codes: [
                    'agreeType',
                    'sexType',
                    'healthyState',
                    'emergencyRelationship',
                    'household',
                    'liveTogether',
                    'backCheckAccepted',
                    'SingaporeRecruitWay',
                    'academicYear',
                    'industryType',
                    'ChinaRecruitWay'
                ]
            }
        });
    };
    useEffect(() => {
        getDict();
    }, []);
    return (
        <Form layout="horizontal" {...formItemLayout}>
            <div className="vv-from-title">简历信息</div>
            <div className={sytleSetting === 'true' ? 'form-Wrap' : ''}>
                <Form1 {...subFormProps} />
                {talentFile && talentFile.length ? (
                    <Form.Item label="附件" vvspan={24} labelCol={{ md: 4 }} wrapperCol={{ md: 20 }}>
                        {talentFile.map(item => (
                            <div key={item.keyName}>
                                <Icon type="paper-clip" />
                                <a
                                    style={{ marginLeft: 8 }}
                                    href={item.url}
                                    // eslint-disable-next-line react/jsx-no-target-blank
                                    target="_blank"
                                    download
                                >
                                    {item.originName}
                                </a>
                            </div>
                        ))}
                    </Form.Item>
                ) : null}
                <Divider style={{ margin: '8px 0 0' }} />
                <Form2 {...subFormProps} />
                <Form3 {...subFormProps} />
                <Form4 {...subFormProps} />
                <Form5 {...subFormProps} />
                <Form6 {...subFormProps} />
                <Form7 {...subFormProps} />
            </div>
        </Form>
    );
};

export default connect(({ common, loading, user, dictionary }) => ({
    common,
    loading,
    user,
    dictionary
}))(Form.create()(Resume));
